<template>
  <div class="course-item">
    <div class="item" @click="getInfoToCourse(index)" v-for="(item, index) in course">
      <div class="pic">
        <img :src="item.image" :title="item.title" />
      </div>
      <div class="info">
        <div class="name">{{item.title}}</div>
        <div class="detail" v-show="item.intro != null">{{item.intro}}</div>
        <div class="teacher" v-show="item.teacher != null">{{item.teacher}}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CourseItem',
  props: {
    course: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  methods: {
    getInfoToCourse(index) {
      // 传入课程数据
      sessionStorage.setItem('courseInfo', JSON.stringify(this.course[index])); //Bearer
      // 调转课程界面
      this.$router.push('/studentCourse');
    },
  },
};
</script>

<style scoped>
.course-item {
  display: flex;
  flex-wrap: wrap;
}
.item {
  height: 240px;
  width: 250px;
  margin: 0 19px 24px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  background-color: #f0f4f7;
  box-shadow: 0 0 10px #aaa;
}

.item .pic {
  width: 230px;
  height: 130px;
  margin-bottom: 10px;
  border-radius: 8px;
  overflow: hidden;
}

.item .pic img {
  height: 100%;
  width: 100%;
}

.item:hover .pic {
  box-shadow: 0 0 8px #999;
}

.item:hover .info .name {
  color: #3a8bff;
}

.item .info .name {
  color: #131b26;
  font-weight: 700;
  font-size: 16px;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  transition: color 0.2s;
}

.item .info .detail,
.item .info .teacher {
  font-size: 12px;
  margin-top: 10px;
}
</style>